<?php
/**
 * kol视频
 * (model)
 */

namespace App\Models\KolManage;


use Illuminate\Database\Eloquent\Model;

class KolVideo extends Model{

    protected $table = 'k_kol_video';

    protected $guarded = [];

    /**
     * 状态
     */
    const STATUS_YES  = 1; //启用
    const STATUS_NO   = 2; //停用
    public static $_status = [
        self::STATUS_YES  => '启用',
        self::STATUS_NO   => '停用',
    ];

    /**
     * 链接类型
     */
    const TYPE_1  = 1; //Video
    const TYPE_2  = 2; //Blog
    const TYPE_3  = 3; //WebSite
    public static $_link_type = [
        self::TYPE_1 => 'Video',
        self::TYPE_2 => 'Blog',
        self::TYPE_3 => 'WebSite',
    ];

    public function kol(){
        return $this->belongsTo(Kol::class, 'kol_code');
    }

    public function video_sku(){
        return $this->hasMany(KolVideoSku::class, 'video_id');
    }

    public static function getDownloadData($res)
    {
        foreach ($res as $model){
            $temp = [
                $model->order_no ?? '',
                $model->kol_id ?? '',
                self::$_link_type[$model->link_type] ?? '',
                $model->link_online_time ?? '',
                $model->link_url ?? '',
                $model->like_num ?? '',
                $model->view_num ?? '',
                $model->comment_num ?? '',
                $model->convert_num ?? '',
                $model->advert_cost ?? '',
                $model->exchange_rate ?? '',
                $model->remark ?? '',
                self::$_status[$model->status] ?? '',
            ];
            yield $temp;
        }
    }

    public static function getModelById($id){
        return self::query()->find($id);
    }

}
